package chap10;
//************************************************************************************
//  DVDCollection.java          Author:GK
//
//  Represents a collection of DVD movies.
//************************************************************************************

import java.text.NumberFormat;

public class DVDCollection implements Comparable
{
    protected DVD[] collection;
    protected int count;
    protected double totalCost;

    private String title, director;
    private int year;
    private double cost;
    private boolean bluray;

    //------------------------------------------------------------------------------------
    //  Constructor: Creates an intially empty collection.
    //------------------------------------------------------------------------------------
    public DVDCollection(String title, String director, int year, double cost, boolean bluray)
    {
        collection = new DVD[100];
        count = 0;
        totalCost = 0.0;

        this.title = title;
        this.director = director;
        this.year = year;
        this.cost = cost;
        this.bluray = bluray;
    }

    //-------------------------------------------------------------------------------------
    //  Adds a DVD to the collection, increasing the size of the collection array if
    //  necessary .
    //------------------------------------------------------------------------------------
    public void addDVD(String title, String director, int year, double cost, boolean bluray)
    {
        if (count == collection.length)
            increaseSize();

        collection[count] = new DVD(title, director, year, cost, bluray);
        totalCost += cost;
        count++;
    }

    //----------------------------------------------------------------------------------------------------
    //Returns a report describing the DVD collection.
    //----------------------------------------------------------------------------------------------------
    public String toString()
    {
        return title + "\t" + director + "\t" + year + "\t" + cost + "\t" + bluray;
    }

    //-------------------------------------------------------------------------------------------------------
//  Increase the capacity of the collection by creating a larger array and copying the existing collection into it.
//-------------------------------------------------------------------------------------------------------
    private void increaseSize()
    {
        DVD[] temp = new DVD[collection.length*2];

        for (int dvd = 0; dvd < collection.length; dvd++)
            temp[dvd] = collection[dvd];

        collection = temp;
    }



    public int compareTo(Object o) {
        int result;

        String name = ((DVDCollection)o).getTitle();
        result = title.compareTo(name);
        return result;
    }

    public String getTitle() {
        return title;
    }

}
